<template>
	<view class="transferCenter">
		<view class="provinceList">
			<scroll-view class="provinceList" scroll-x="true">
				<view id="demo1" class="provinceItem" v-for="(item,index) in provinceList"
					:class="currIndex1==index ? 'selected' :''" @click="handleCurrprovince(item,index)">{{item.name}}
				</view>
			</scroll-view>
		</view>

		<view class="selectList">
			<view class="selectitem" v-for="(item,index) in listData" @click="handleSelect(index)">
				<view class="">
					{{item.name}}
				</view>
				<view class="">
					<image v-if="currIndex2 ==index" :src="imaurl+'fill.png'" style="width: 36rpx;height: 36rpx;"
						mode=""></image>
					<image v-else :src="imaurl+'null.png'" style="width: 36rpx;height: 36rpx;" mode="">
					</image>
				</view>
			</view>
		</view>

		<view class="btns" @click="handleSubmit">
			确定
		</view>

	</view>
</template>

<script>
	import {
		getprovince,
		getdailiandgp
	} from "@/api/api.js"
	export default {
		data() {
			return {
				currIndex1: 0,
				currIndex2: 0,
				provinceList: [],
				provinceId: "", //省份id
				gid: "", //工棚id
				listData: [],
				imaurl: "https://szgb.tongchengbang.cc/img/image/",
			}
		},
		async onLoad() {
			await this.handlegetprovince()
			await this.handlegetdailiandgp()
		},
		methods: {
			async handlegetprovince() {
				let res = await getprovince()
				this.provinceList = res.data
				this.provinceId = this.provinceList[0].id
			},
			async handlegetdailiandgp() {
				let res = await getdailiandgp({
					id: this.provinceId,
					type: "2"
				})
				this.listData = res.data
				this.gid = this.listData[0].id
			},
			handleCurrprovince(item, index) {
				this.currIndex1 = index
				this.provinceId = this.provinceList[index].id
				this.handlegetdailiandgp()
			},
			handleSelect(index) {
				this.currIndex2 = index
				this.gid = this.listData[index].id
			},
			handleSubmit() {
				let data = {
					gid: this.gid,
					gName: this.listData[this.currIndex2].name
				}
				uni.setStorageSync('gData', data)
				uni.navigateBack({
					delta: 1
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.transferCenter {
		.provinceList {
			width: 750rpx;
			height: 124rpx;
			background: #FFFFFF;
			padding: 5rpx 30rpx;
			box-sizing: border-box;
			display: flex;
			white-space: nowrap;

			.provinceItem {
				width: 184rpx;
				height: 84rpx;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				border: 2rpx solid #EEEEEE;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 32rpx;
				color: #333333;
				line-height: 84rpx;
				text-align: center;
				margin-right: 20rpx;
				display: inline-block;
			}

			.selected {
				border: 2rpx solid #00BF52;
				color: #00BF52;
			}
		}

		.selectList {
			margin-top: 20rpx;

			.selectitem {
				display: flex;
				align-items: center;
				width: 750rpx;
				height: 124rpx;
				background: #FFFFFF;
				margin-bottom: 1rpx;
				padding: 30rpx 40rpx;
				box-sizing: border-box;
				justify-content: space-between;
			}
		}

		.btns {
			width: 630rpx;
			height: 88rpx;
			background: #00BF52;
			border-radius: 200rpx 200rpx 200rpx 200rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 88rpx;
			text-align: center;
			position: absolute;
			bottom: 120rpx;
			left: 50%;
			margin-left: -315rpx;
		}

	}
</style>